package com.rla.common.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.Map;

public class EasyExcelCellListener extends AnalysisEventListener<Map<Integer,String>> {

    private String cellValue;
    private int targetRow;
    private int targetColumn;

    private boolean isCellRead = false;

    public EasyExcelCellListener(int targetRow, int targetColumn) {
        this.targetRow = targetRow;
        this.targetColumn = targetColumn;
    }

    @Override
    //invoke方法的参数类型跟随实现的ReadListener的类型
    public void invoke(Map<Integer,String> map, AnalysisContext analysisContext) {
        if(isCellRead){
            return;
        }
        int currentRow = analysisContext.readRowHolder().getRowIndex()+1;
        if(currentRow == targetRow ){
            cellValue = map.get(targetColumn-1);
            isCellRead = true;
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

    public String getCellValue() {
        return cellValue;
    }


}
